<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        let user = {
            name: "John",
            size: {
                height: 185,
                weight: 75,
            }
        };
        let id = Symbol("id");

        user[id] = 1;

        let cloneUser = cloneDeep(user);

        cloneUser.size.height = 190;
        cloneUser.size.weight = 80;
        cloneUser.name = "Jack";
        cloneUser[id] = 2;

        alert(user[id] + " " + JSON.stringify(user));
        alert(cloneUser[id] + " " + JSON.stringify(cloneUser));

        function cloneDeep(obj) {
            let newobj = obj.constructor === Array ? [] : {};
            // constructor 属性返回对创建此对象的数组函数的引用。创建相同类型的空数据

            if (typeof obj !== 'object') {
                return;
            } else {
                for (var i in obj) {
                    if (typeof obj[i] === 'object') {
                        newobj[i] = cloneDeep(obj[i]);
                    } else {
                        newobj[i] = obj[i];
                    }
                }
            }
            return newobj;
        }
    </script>
</head>
<body></body>
</html>